Max Points on a Line
Question
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
Analysis
- map.put((double)Integer.MIN_VALUE,1); 可能整个序列都是相同点,他们的斜率用MIN_VALUE表示
- 利用dup变量记录有多少个重复的点
- 每次进入一个新的坐标点比较的时候记住map.clear
- 计算key的时候必须+0.0,否则无法通过所有点纵坐标相同的情况
Code
|
|
Palindrome Partitioning II
Question
We are playing the Guess Game. The game is as follows:
I pick a number from 1 to n. You have to guess which number I picked.
Every time you guess wrong, I’ll tell you whether the number I picked is higher or lower.
However, when you guess a particular number x, and you guess wrong, you pay $x. You win the game when you guess the number I picked.
Example:
|
|
Given a particular n ≥ 1, find out how much money you need to have to guarantee a win.
Analysis
Code
|
|